const {
	mysql,
	pool,
	router,
	Result,
	Myquery
} = require('../connect');
// const express = require('express')
// const router = express.Router()

// router.get('/',(req,res)=>{
//     // pool.getConnection((err,conn)=>{
//     // 	conn.query('SELECT * FROM students',(e,r)=>{
//     // 		if (err) throw err;
//     // 		res.json(new Result({data:r,code:200}))
//     // 	});
//     // 	conn.release();//释放
//     // })
//     Myquery('SELECT * FROM students',(e,r)=>{
// 		if (err) throw err;
// 		res.json(new Result({data:r,code:200}))
//     })
// })

router.get('/', (req, res) => {
	console.log('login')
	var sql = 'SELECT * FROM node_one',
		id = req.params.id || req.query.id || req.body.id;
	if (id) {
		sql = "select * from node_one where ?? = ?"
		var inserts = ['id', id]
		sql = mysql.format(sql, inserts)
	}
	console.log(req.query, req.params, req.body) //"?id=1"=>req.query,'/:id'=>req.params,post {id:1}=>req.body
	new Myquery(sql, (err, r) => {
		if (err) throw err;
		res.json(new Result({
			data: r,
			code: 200
		}))
	})
	// return res.json({query:req.query,data:req.params,json:req.body})
})

router.get('/navigate', (req, res) => {
	res.send("<a href='/usersinfo/navigate'>usersinfo-navigate</a><br/><a href='/userinfo/navigate'>userinfo-navigate</a>")
})

// router.post('/',(req,res)=>{
// 	var sql = 'SELECT * FROM students',
// 	console.log(req.query,req.params,req.body)//"?id=1"=>req.query,'/:id'=>req.params,post {id:1}=>req.body
//     new Myquery(sql,(err,r)=>{
// 		if (err) throw err;
// 		res.json(new Result({data:r,code:200}))
//     })
// })

module.exports = router;